
import * as UmfDialog from '../../utils/UmfDialog';
import LoginUtils from '../../model/LoginUtils';
import * as Constants from '../../common/Constants';
const app = getApp();

Page({
    data: {
        isAgent: false,
        canSearchStores: false,
        canSearchProfit: false,
        canFetchBillDoc: false,

        canManageAgent: false
    },

    onShow: function (options) {
        if (app.globalData.states.isLoginProcess) {
            return;
        }
        let isAgent = app.globalData.userData.isAgent();
        let canSearchStores = app.globalData.userData.permConfig.canSearchStores();
        let canSearchProfit = app.globalData.userData.permConfig.canSearchProfit();
        let canFetchBillDoc = app.globalData.userData.permConfig.canFetchBillDoc();
        let canManageAgent = app.globalData.userData.permConfig.canManageAgent();

        this.setData({
            isAgent: isAgent,
            canSearchStores: canSearchStores,
            canSearchProfit: canSearchProfit,
            canFetchBillDoc: canFetchBillDoc,
            canManageAgent: canManageAgent,

            firstModel: isAgent || (canSearchStores || canSearchProfit || canFetchBillDoc)
        });
    },

    /**
     * 退出登录
     * @param ee
     */
    onExit: function (ee) {
        UmfDialog.show("是否退出当前账号", ()=> {
            LoginUtils.clearLoginData();

            wx.navigateTo({
              url: '../login/login?from=' + Constants.LoginFrom.LOGOUT
            });
        }, true);
    }

});